package com.ueip.backend.utils;

import com.ueip.backend.pojo.User;
import com.ueip.backend.service.impl.utils.UserDetailsImpl;
import com.ueip.backend.vo.Result;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;

@Component
public class IdentityAuthenticationUtil {

    public static User getCurUser() {
        UsernamePasswordAuthenticationToken authenticationToken =
                (UsernamePasswordAuthenticationToken) SecurityContextHolder.getContext().getAuthentication();
        UserDetailsImpl loginUser = (UserDetailsImpl) authenticationToken.getPrincipal();
        User user = loginUser.getUser();
        return user;
    }
}
